<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>诗篇在线建站系统登录</title>
<meta name="description" content="面向对象，基于freemarker的模板，完全在网页中进行">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<link rel="stylesheet" href="/logintpls/login.css">
<script src="http://yui.m3958.com/3.5.1/build/yui/yui-min.js"></script>
</head>
<body>
	<div class="wrapper">
		<div class="google-header-bar">

			<div class="header content clearfix">
				 <h1 class="logo" id="login-title"></h1>
				<span class="signup-button"> 第一次使用？ <a id="link-signup" class="g-button g-button-red"
					href="/signup.html#next=${next}" tabindex="7"> 创建帐户 </a> </span>
			</div>
		</div>

		<div class="main content clearfix">
			<div class="sign-in">
				<div class="signin-box">
					<h2>
						登录 <strong></strong>
					</h2>
					<form id="loginform" action="/login" method="post">
						<input type="hidden" name="_bianmachecker" value="我是utf-8"></input>
						<input type="hidden" name="_loginextratask" value=""></input>
						
						<label>
							<strong class="email-label">用户名</strong> <input type="text"
							name="username" id="username" value="" tabindex="1">
							<span role="alert" class="errormsg" id="errormsg_0_username">
  								请输入您的用户名或电子邮件地址或手机号码。
  							</span>
							 </label>
						<label>
							<strong class="passwd-label">密码</strong> <input type="password"
							name="password" id="password" tabindex="2">
							<span role="alert" class="errormsg" id="errormsg_0_password">
  								您输入的用户名或者密码错误！
  							</span>							
						 </label>
						<#if showCaptcha>
						<label>
							<strong class="passwd-label">验证码</strong> <input type="text"
							name="answer" id="answer" tabindex="3">
							<span role="alert" class="errormsg" id="errormsg_0_answer">
  								请输入正确的验证码！
  							</span>								
							</label>
						<table>
							<tr>
								<td><div id="captchaImgC"></div></td>
								<td><a href="#" id="refreshCaptcha" tabindex="4">换一个图片</a></td>
							</tr>
						</table>
						</#if>
						<input	type="submit" class="g-button g-button-submit" name="signIn"
							id="signIn" value="登录" tabindex="6">
						 <label class="remember">
							<input type="checkbox" name="_persistedLogin"
							id="persistedLogin" value="1y" tabindex="5"/> <strong
							class="remember-label"> 保持登录状态 </strong> </label>
					</form>
					<p>第三方登录：<a href="/openid.html#next=${next}" id="link-openid">openid,google,yahoo,QQ</a></p>
					<p>测试帐号：demo，密码：demo</p>
					<ul>
						<!-- <li><a id="link-forgot-passwd"	href="#" target="_top"> 无法访问您的帐户吗？ </a></li> -->
					</ul>
				</div>
			</div>
			<div class="product-info mail" id="login-description">

			</div>
			<div id="cc_iframe_parent"></div>
		</div>
		<div class="google-footer-bar">
			<div class="footer content clearfix">
				<ul>
					<li>© 2011 奉化市诗篇网络科技有限公司</li>
				</ul>
			</div>
		</div>
	</div>
	
	<script type="text/x-template" id="sitebuilder-template">
				<p>诗篇建站系统的理念是：面向对象的数据 + 模板，摆脱束缚，自由的开发网站。具有以下特点：</p>
				<ul class="features">
					<li>
						<p class="title">非常简单</p>
						<p>
							相当于面向对象版的asp，只不过模板变成了freemarker(velocity)。
						</p></li>
					<li>
						<p class="title">通用化的插件</p>
						<p>我们开发了通用的投票、评论、计数、自定义表单等功能。</p></li>
					<li>
						<p class="title">没有部署过程</p>
						<p>
							你不需要了解操作系统，数据库，在我们提供的对象内发挥想象力即可。
						</p></li>
				</ul>
	</script>
	
	<script type="text/x-template" id="workflowy-template">
				<p>秩序，以分层的列表组织文字：</p>
				<ul class="features">
					<li>
						<p class="title">非常简单</p>
						<p>
							只有排列有序的列表，任意层次的深度。
						</p></li>
					<li>
						<p class="title">自动同步</p>
						<p>不管是办公室还是家里，保持你最新记录的内容。</p></li>
					<li>
						<p class="title">推荐使用场景</p>
						<p>
							会议记录。
						</p></li>
				</ul>
	</script>
	
	<script type="text/javascript">
	YUI({combine: true,
		comboBase: 'http://yui.m3958.com/combo?',
		root : '3.5.1/build/'}).use('event','io','json','node',
			function(Y){
				var showCaptcha = ${showCaptcha?string("true","false")};
				var usernameNode = Y.one('#username');
				var passwordNode = Y.one('#password');
				
				var answerNode = null,cc = null,captchaImg = null;
				if(showCaptcha){
					answerNode = Y.one('#answer');
					answerNode.set('value','');
					cc = Y.one('#captchaImgC');
					cc.setContent('<img src="' + '/simpleImg?' + Math.random() + '" id="captchaImg"/>');
					captchaImg = Y.one('#captchaImg');
				}
				var isDebug = false;
				if(window.location.href.indexOf("127.0.0.1") != -1)isDebug = true;
				
				var next = "${next}"; 
				var nextUrl = "/FirstGwt.html";
				
				var loginDescription = Y.one('#login-description');
				var loginTitle = Y.one('#login-title');
				
				if(next == 'fhtrade'){
					nextUrl = "/Fhtrade.html";
				}else if(next == 'webtool'){
					nextUrl = "/Webtool.html";
				}else if(next == 'workflow'){
					nextUrl = "/workflow.html";
					loginTitle.setContent('秩序-让大脑有序');
					loginDescription.setContent(Y.one('#workflowy-template').getContent());
				}else if(next == 'csshtml'){
					nextUrl = "/m3958-module-html/cssconsole.html";	
				}else{
					loginTitle.setContent('诗篇在线建站系统');
					loginDescription.setContent(Y.one('#sitebuilder-template').getContent());
				}
				if(isDebug){
					nextUrl += "?gwt.codesvr=127.0.0.1:9997";
				}
				var linkSignup = Y.one('#link-signup');

				var signuphref = linkSignup.get('href');
				if(isDebug)signuphref += '&debug=true';
				linkSignup.set('href',signuphref);
				
				var linkOpenid = Y.one('#link-openid');
				var linkOpenidHref = linkOpenid.get('href');
				if(isDebug)linkOpenidHref += '&debug=true';
				linkOpenid.set('href',linkOpenidHref);
				
				(function(){
					var tH = {
							success: function(id, o, args) {
										var res = Y.JSON.parse(o.responseText);
										var status = res.response.status;
										var data = res.response.data;
										if(status == 0){
											   if(Y.Lang.isArray(data) && data.length == 1){
													   window.location.href=nextUrl; 
												   }
										}else{
											;
										}
									 },
							failure: function(id, o, args) {
									  Y.log(o);
									  alert("发生未知故障！");
									 }
						};
					
					var cfg = {
							method:'GET',
							on: {
								success: tH.success,
								failure: tH.failure
							},
							context: tH
						};
					Y.io('/notrpclogin?_loginstatusdetect=true', cfg);
				})();
				
				var hideAllError = function(){
		        	usernameNode.removeClass('form-error');
		        	passwordNode.removeClass('form-error');
		        	if(showCaptcha){
		        		answerNode.removeClass('form-error');
		        	}
		        	showhideerror('errormsg_0_username',false);
		        	showhideerror('errormsg_0_password',false);
		        	showhideerror('errormsg_0_answer',false);
				};
				
				var showhideerror = function(name,show){
					if(show){
						if("username" == name){
							usernameNode.addClass('form-error');
							Y.one('#errormsg_0_username').setStyle('display','block');
							usernameNode.focus();
						}else if("password" == name){
							passwordNode.addClass('form-error');
							Y.one('#errormsg_0_password').setStyle('display','block');
							passwordNode.focus();
						}else if("answer" == name && showCaptcha){
							answerNode.addClass('form-error');
							Y.one('#errormsg_0_answer').setStyle('display','block');
							answerNode.focus();
						}
					}else{
						if("username" == name){
							usernameNode.removeClass('form-error');
							Y.one('#errormsg_0_username').setStyle('display','none');
						}else if("password" == name){
							passwordNode.removeClass('form-error');
							Y.one('#errormsg_0_password').setStyle('display','none');
						}else if("answer" == name && showCaptcha){
							answerNode.removeClass('form-error');
							Y.one('#errormsg_0_answer').setStyle('display','none');
						}
					}
				};
				
				usernameNode.focus();
				
				if(showCaptcha){
					answerNode.set('value','');
					Y.on('click',function(e){
						e.preventDefault();
						captchaImg.set('src','/simpleImg?' + Math.random());
					},'#refreshCaptcha');
				}
		        
		        var formnode = Y.one('#loginform');
		        
		        formnode.on('submit',function(e){
		        	if(usernameNode.get('value').length < 2){
						showhideerror("username",true);
						e.preventDefault();
		        		return;
		        	}else{
		        		showhideerror("username",false);
		        	}
		        	
		        	if(passwordNode.get('value').length < 3){
		        		showhideerror("password",true);
		        		e.preventDefault();
		        		return;
		        	}else{
		        		showhideerror("password",false);
		        	}
		        	
		        	if(showCaptcha){
			        	if(answerNode.get('value').length != 5){
			        		showhideerror("answer",true);
			        		e.preventDefault();
			        		return;
			        	}else{
			        		showhideerror("answer",false);
			        	}
		        	}
		        });
		        
		        usernameNode.set('value',"${username!""}");
		        
		        <#list errorScripts![] as errorScript>
		        	${errorScript}
		        </#list>
		        
	});
	</script>
</body>
</html>
